<template>
  <div class="prize-list">
        <div class="banner">
        <img src="http://files.wabei.cn/2022Vote/bannerV3.jpg" alt="">
      </div>
	      <div class="prize-name">
          <div class="prize-detail">
              	<h4>
									{{type==1?"参评董事长":"参评企业"}}：<span  class="join-number">{{prizeList.totalCompanies}}</span>
									当前总票：<span class="join-number">{{prizeList.totalVotes}}</span>
								</h4>
								<ul>
									<li :class="idx>98?'three':(idx>998?'four':'')" v-for="(prizeItem,idx) in prizeList.list" :key="idx">
										<div>
											<span class="number">
											<!-- {{prizeItem.rateNum}} -->
                       {{idx+1}}
											</span>
											<span  v-if="type==1" class="company-code" @click="toCompanyPage(prizeItem.companyID,prizeItem.pollID)">
												{{prizeItem.ceo}} - {{prizeItem.stockName}}
											</span>
											<span v-else class="company-code" @click="toCompanyPage(prizeItem.companyID,prizeItem.pollID)">
												{{prizeItem.stockName}}&nbsp;({{prizeItem.stockCode}})
											</span>
											<span class="current-votes">
													当前票数：{{prizeItem.votes}}
											</span>
											<button @click="toCompanyPage(prizeItem.companyID,prizeItem.pollID)">
												投票
											</button>
										</div>
									</li>
								</ul>
          </div>		
			</div>
  </div>
</template>
<script>
export default {
  name: "enterprise",
  data() {
    return {
      type: 1,
      prizeList: {}
    };
  },
  methods: {
    loadList() {
      var that = this;
     var idx = this.$route.params.type;
      this.type = idx;
      var that = this;
      this.$ajax
        .get(that.commenPath + "/vote/polls/0/" + idx + "/all")
        .then(function(res) {
          if (res.data.code == 0) {
            var data = res.data.data;
            that.prizeList = data;
            that.prizeList.list=that.sortArr(that.prizeList.list)
          } else {
            that.$vux.toast.text(data.message, "middle");
          }
        })
        .catch(function(res) {
          console.log(res);
        });
    },
    toCompanyPage(code, pollID) {
      // this.$router.push({ path: "/vote/companyDetail?code=" + code });
      window.location.href="../../../../static/page4/index.html?codes="+code
    },
    sortArr:function(arr){
      arr.forEach(function(value, index, array) {
        if(index==0){
          arr[index].rateNum=1
        }else{
          arr[index].votes==arr[index-1].votes?arr[index].rateNum=arr[index-1].rateNum:array[index].rateNum=arr[index-1].rateNum+1
        }
      });
      return arr
    },
    toVote(idx, k1) {
      //奖项编号
      if (!idx) {
        return;
      }
      var that = this;
      this.$ajax
        .post(
          that.commenPath +
            "/vote/vote/" +
            idx +
            "/" +
            that.getCookie("accesskey")
        )
        .then(function(res) {
          var data = res.data;
          if (data.code == 0) {
            that.$vux.toast.text("投票成功！", "middle");
            that.prizeList.totalVotes++;
            that.prizeList.list[k1].votes++;
          } else {
            that.$vux.toast.text(data.message, "middle");
          }
        })
        .catch(function() {
          that.$vux.toast.text("出错啦!", "middle");
        });
    }
  },
  created() {
    this.loadList();
  },
  mounted() {
    this.$router.afterEach((to, from, next) => {
      window.scrollTo(0, 0);
    });
  }
};
</script>
<style>
</style>


